// 定义store

import {defineStore} from "pinia"
import { useCart } from "../components/carts"
export const useUser = defineStore('users',{
    state(){
        return{
            username:'卢本伟',
            count:10,
            arr:['吃','喝','玩'],
            data:[]

        }
    },
    getters:{
        reverseName(state){
            return state.username.split("").reverse().join("")
        },
        newArr(state){
            return state.arr.push(this.reverseName)
            return state.arr
        }
    },
    actions:{
      async  fetch_data(a,b){
            // console.log(a,b)
            let cartStore = useCart()
            console.log( cartStore.cart);
            
            try{
            let res = await fetch('/api/data/index.json')
            .then(body=>body.json())
            console.log(res);
            this.data=res.data
           }catch(e){
            console.log(e);          
           }
           
        }
    }
})